package com.yzk.auction.service;

import com.yzk.auction.dao.SecondCategoryDao;
import com.yzk.auction.entity.Category;
import com.yzk.auction.entity.SecondCategory;
import com.yzk.auction.utils.JDBCUtils;
import com.yzk.auction.utils.PageModel;
import org.apache.commons.dbutils.QueryRunner;

/**
 * @author： lys
 * @date： 2020/8/20 11:16
 * @类名： SecondCategoryDao
 * @Title：
 */

public class SecondCategoryService {
    /**
     * 查询所有二级分类
     * @return
     * @throws Exception
     */
    public PageModel findSecondCategoryAll(int page, int rows) throws Exception {
        SecondCategoryDao dao = new SecondCategoryDao();
        if(rows == 0) {
            throw new RuntimeException("无效的rows参数");
        }
        return dao.findSecondCategoryAll(page, rows);
    }

    /**
     * 根据id查信息
     * @param second_cid
     * @return
     * @throws Exception
     */
    public Category findfindSecondCategoryById(int second_cid) throws Exception {
        SecondCategoryDao dao = new SecondCategoryDao();
        return dao.findfindSecondCategoryById(second_cid);
    }

    /**
     * 通过名字查询一级分类id
     * @param first_cname
     * @return
     * @throws Exception
     */
    public int findfindSecondCategoryByName(String first_cname) throws Exception {
        SecondCategoryDao dao = new SecondCategoryDao();
        return dao.findfindSecondCategoryByName(first_cname);
    }

    /**
     * 插入二级分类信息
     * @param secondCategory
     * @throws Exception
     */
    public void insertSecondCategory(SecondCategory secondCategory) throws Exception {
        SecondCategoryDao dao = new SecondCategoryDao();
        dao.insertSecondCategory(secondCategory);
    }

    /**
     * 删除二级分类信息
     * @param second_cid
     * @throws Exception
     */
    public void deleteSecondCategory(int second_cid) throws Exception {
        SecondCategoryDao dao = new SecondCategoryDao();
        dao.deleteSecondCategory(second_cid);
    }

    /**
     * 更新二级分类信息
     * @param secondCategory
     * @throws Exception
     */
    public void updateSecondCategory(SecondCategory secondCategory) throws Exception {
        SecondCategoryDao dao = new SecondCategoryDao();
        dao.updateSecondCategory(secondCategory);
        QueryRunner runner = new QueryRunner(JDBCUtils.getDataSource());
    }
}
